#!/usr/bin/env python
# -*- coding: utf-8 -*-
###################################################################
# Copyright(c) Genecast, all rights reserved
# @file        : plot_door.py
# @author      : zhang.xiancang
# @mail        : zhang.xiancang@genecast.com.cn
# @revision    : Tue Nov  8 14:55:16 2022
# @description : 
###################################################################
import matplotlib.pyplot as plt
from n_door_zxc import n_door_zxc
import argparse
import time


def plot_door(argv):
    test_n = [1000,10000,100000,1000000]
    # test_n = [1000,10000]
    door_n = 3
    number_0_x = 0
    number_1_x = 0
    list_0 = []
    list_1 = []
    list_time = []
    door_games_0 = n_door_zxc(argv,0)
    door_games_1 = n_door_zxc(argv,1)
    for number in test_n:
        start_time = time.time()
        for change in range(1,int(number)+1):
            if door_games_0.paly_games() == 0:
                number_0_x +=1
            if door_games_1.paly_games() == 0:
                number_1_x +=1
        finish_time = time.time()
        values_a = number_0_x/int(number)
        list_0.append(values_a)
        values_b = number_1_x/int(number)
        list_1.append(values_b)
        sum_time = finish_time - start_time
        list_time.append(sum_time)
    fig = plt.figure()
    fig.suptitle('Figure: Simulation times and obtain treasure probability')
    plt.plot(test_n,list_0, label='change door')
    plt.plot(test_n,list_1, label='no_change door')
    plt.xticks(range(0,1000000,200000)) 
    plt.xlabel('simulation times')
    plt.ylabel('probability')
    plt.legend()
    plt.savefig("probability_simulation.png")
    # plt.show()
    fig = plt.figure()
    fig.suptitle('Figure: Simulation times and run times')
    plt.scatter(test_n,list_time, label='run time')
    plt.xticks(range(0,1000000,200000)) 
    plt.xlabel('simulation times')
    plt.ylabel('run time(s)')
    plt.legend()
    plt.savefig("run_times_simulation.png")
    # plt.show()


def my_parser():
    parser = argparse.ArgumentParser(description="n-door 游戏概率")
    parser.add_argument('-n', '--door_n', help = "共有n扇门",default=3,type=int,required = False)
    argv = parser.parse_args()
    return argv


if __name__ == "__main__":
    argv = my_parser()
    plot_door(argv)

